package edu.univercidade.tcc.web;

import java.util.Arrays;

import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import edu.univercidade.tcc.server.model.Issue;
import edu.univercidade.tcc.server.model.Project;
import edu.univercidade.tcc.server.service.IssueService;
import edu.univercidade.tcc.server.service.ProjectService;


/**
 * This class is generated by <b>jasperoo setup</b>.
 * Request mapping methods are added by <b>jasperoo add</b> or <b>jasperoo all</b>.
 * 
 * <b>ANYTHING ADDED AFTER THE CLOSING BRACE WILL BE DELETED BY <u>jasperoo add</u>!</b>
 */
@RequestMapping("/reports")
@Controller
public class ReportController {

/*
 * The template for the "List" Request mapping methods is: 
 *
 *	@RequestMapping(value ="/**ENTITY_NAME_LOWER**List/{format}", method = RequestMethod.GET)
 *	public String report**ENTITY_NAME**List(ModelMap modelMap, @PathVariable("format") String format) {
 *		JRBeanCollectionDataSource jrDataSource = new JRBeanCollectionDataSource(**ENTITY_NAME**.findAll**REPORT_TITLE**(),false);
 *		modelMap.put("reportData", jrDataSource);
 *		modelMap.put("format", format);
 *		return "**ENTITY_NAME_LOWER**ReportList";
 *	}
 */

	@Autowired
	private transient IssueService issueService;
	
	@Autowired
	private transient ProjectService projectService;
	
	@RequestMapping(value ={"/issueList/{format}","/tarefaList/{format}"}, method = RequestMethod.GET)
	public String reportIssueList(ModelMap modelMap, @PathVariable("format") String format) {
		JRBeanCollectionDataSource jrDataSource = new JRBeanCollectionDataSource(issueService.findAllIssues(),false);
		modelMap.put("reportData", jrDataSource);
		modelMap.put("format", format);
		return "issueReportList";
	}

	@RequestMapping(value ={"/issueDetail/{id}/{format}","/tarefaDetail/{id}/{format}"}, method = RequestMethod.GET)
	public String reportIssueDetail(ModelMap modelMap, @PathVariable("id") Long id, @PathVariable("format") String format) {
		JRBeanCollectionDataSource jrDataSource = new JRBeanCollectionDataSource(Arrays.asList(new Issue[]{issueService.findIssue(id)}),false);
		modelMap.put("reportData", jrDataSource);
		modelMap.put("format", format);
		return "issueReportDetail";
	}

	@RequestMapping(value ={"/projectList/{format}","projetoList/{format}"}, method = RequestMethod.GET)
	public String reportProjectList(ModelMap modelMap, @PathVariable("format") String format) {
		JRBeanCollectionDataSource jrDataSource = new JRBeanCollectionDataSource(projectService.findAllProjects(),false);
		modelMap.put("reportData", jrDataSource);
		modelMap.put("format", format);
		return "projectReportList";
	}

	@RequestMapping(value ="/projectDetail/{id}/{format}", method = RequestMethod.GET)
	public String reportProjectDetail(ModelMap modelMap, @PathVariable("id") Long id, @PathVariable("format") String format) {
		JRBeanCollectionDataSource jrDataSource = new JRBeanCollectionDataSource(Arrays.asList(new Project[]{projectService.findProject(id)}),false);
		modelMap.put("reportData", jrDataSource);
		modelMap.put("format", format);
		return "projectReportDetail";
	}

}